<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <meta content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0" name="viewport" />
    <meta content="yes" name="apple-mobile-web-app-capable" />
    <meta content="black" name="apple-mobile-web-app-status-bar-style" />
    <meta content="telephone=no" name="format-detection" />
    <title>完善资料</title>
    <link rel="stylesheet" href="../css/ydui.css">
    <link rel="stylesheet" href="../css/style.css">
    <link rel="stylesheet" href="../iconfont/iconfont.css">
    <script src="../js/ydui.flexible.js"></script>
</head>

<body>
    <div class="g-view perfectdataPage" id="perfectdataPage">
        <div class="m-celltitle" style="margin-top: 0.2rem;">信息资料均为必填项</div>
        <div class="m-cell">
            <div class="cell-item">
                <div class="cell-left">
                    <span>真实姓名：</span>
                </div>
                <div class="cell-right">
                    <input id="realname" type="text" class="cell-input" placeholder="请输入真实姓名">
                </div>
            </div>
            <div class="cell-item">
                <div class="cell-left">
                    <input id="phone" type="number" pattern="[0-9]*" class="cell-input" placeholder="请输入手机号码" autocomplete="off">
                </div>
                <div class="cell-right">
                    <a @click="gitcode" id="codetext" href="javascript:;" class="btn btn-warning">获取验证码</a>
                </div>
            </div>
            <div class="cell-item">
                <div class="cell-left">
                    <span>验&nbsp;&nbsp;证&nbsp;&nbsp;码：</span>
                </div>
                <div class="cell-right">
                    <input id="code" type="text" class="cell-input" placeholder="请输入验证码">
                </div>
            </div>
            <div class="cell-item">
                <div class="cell-left">
                    <span>销售品牌：</span>
                </div>
                <div class="cell-right">
                    <input id="brand" type="text" class="cell-input" placeholder="请输入销售品牌">
                </div>
            </div>
        </div>
        <div class="m-celltitle">主营产品</div>
        <div class="m-cell">
            <div class="cell-item">
                <textarea id="product" placeholder="请输入主营产品" class="cell-textarea" name="" id="" cols="30" rows="10"></textarea>
            </div>
        </div>
        <div class="m-celltitle">负责地区（可多选）：只为您推送负责地区的商机</div>
        <div class="area" style="margin-bottom: 1rem">
            <div class="m-cell" id="setupPage">
                <label class="cell-item" v-for="(item, index) in province_arry" :key="index">
                    <span class="cell-left">{{item.name}}</span>
                    <label class="cell-right">
                        <input :value="item.id" type="checkbox" name="checkbox" />
                        <i class="cell-checkbox-icon"></i>
                    </label>
                </label>
            </div>
        </div>
        <button @click="checkCode" class="btn-block btn-primary">保存设置</button>
    </div>
    <footer class="m-tabbar tabbar-fixed">
        <a href="../index.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe617;</i>
            </span>
            <span class="tabbar-txt">询盘商机</span>
        </a>
        <a href="../setup.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:20px" class="icon iconfont">&#xe698;</i>
            </span>
            <span class="tabbar-txt">设置商机</span>
        </a>
        <a href="../release.html" class="tabbar-item">
            <span class="tabbar-icon">
                <i style="font-size:22px" class="icon iconfont">&#xe662;</i>
            </span>
            <span class="tabbar-txt">发布商机</span>
        </a>
        <a href="../vip.html" class="tabbar-item tabbar-active">
            <span class="tabbar-icon">
                <i style="font-size:25px" class="icon iconfont">&#xe67e;</i>
            </span>
            <span class="tabbar-txt">会员中心</span>
        </a>
    </footer>
    <script src="../js/jquery-3.3.1.min.js"></script>
    <script src="../js/vue.js"></script>
    <script src="../js/ydui.js"></script>
    <script src="../js/nuoxia.js"></script>
    <script src="../js/nuoxia.config.js"></script>
    <script>
        window.onload = function () {
            var token = window.localStorage.getItem("token")
            var perfectdataPage = new Vue({
                el: "#perfectdataPage",
                data: {
                    province_arry: []
                },
                filters: {

                },
                mounted: function () {
                    this.addresslist();
                },
                methods: {
                    addresslist: function () {
                        var _this = this;
                        $.ajax({
                            type: "get",
                            url: paraurl + "api/region/province?tm=" + tm,
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.province_arry = data.data;
                                }
                            }
                        })
                    },
                    gitcode: function () {
                        var $t = $("#codetext");
                        if ($t.text() == "获取验证码") {
                            var phone = $("#phone").val();
                            if (zm.rules("isphone", phone, "手机号格式错误！") == false) {
                                return false;
                            }
                            $.ajax({
                                type: "post",
                                url: paraurl + "api/common/sendSms?token=" + token + "&tm=" + tm,
                                data: {
                                    "mobile": phone,
                                    "event": "wanshan"
                                },
                                success: function (data) {
                                    if (data.code == 1) {
                                        var last = 60;
                                        $t.addClass("btn-disabled").removeClass("btn-warning")
                                        var timer = setInterval(function () {
                                            if (last == 0) {
                                                $t.text("获取验证码");
                                                $t.removeClass("btn-disabled").addClass("btn-warning")
                                                clearInterval(timer);
                                            } else {
                                                last--;
                                                $t.text("重新发送(" + last + ")s");
                                            }
                                        }, 1000);
                                    } else {
                                        YDUI.dialog.alert(data.msg);
                                    }
                                }
                            })
                        }
                    },
                    checkCode:function(){
                        var phone = $("#phone").val();
                        var code = $("#code").val();
                        var _this=this;
                        if (zm.rules("isnull", phone, "请输入手机号！") == false) {
                            return false;
                        }
                        if (zm.rules("isphone", phone, "手机号格式错误！") == false) {
                            return false;
                        }
                        if (zm.rules("isnull", code, "请输入验证码！") == false) {
                            return false;
                        }
                        $.ajax({
                            type: "post",
                            url: paraurl + "api/common/checkCode?token=" + token + "&tm=" + tm,
                            data: {
                                "event": "wanshan",
                                "mobile": phone,
                                "code": code
                            },
                            success: function (data) {
                                if (data.code == 1) {
                                    _this.notice()
                                } else {
                                    YDUI.dialog.alert(data.msg);
                                }
                            }
                        })
                    },
                    notice: function () {
                        var realname = $("#realname").val();
                        var phone = $("#phone").val();
                        var brand = $("#brand").val();
                        var product = $("#product").val();
                        if (zm.rules("isnull", realname, "请输入真实姓名！") == false) {
                            return false;
                        }                        
                        if (zm.rules("isnull", brand, "请输入销售品牌！") == false) {
                            return false;
                        }
                        if (zm.rules("isnull", product, "请输入主营产品！") == false) {
                            return false;
                        }
                        var names = $("#setupPage input[name='checkbox']");
                        var values = [];
                        for (var i = 0; i < names.length; i++) {
                            if (names[i].checked) {
                                values.push(names[i].value)
                            }
                        }
                        values = values.toString();
                        if (values == "") {
                            YDUI.dialog.alert('请选择负责地区！');
                            return false;
                        }
                        $.ajax({
                                type: "post",
                                url: paraurl + "api/user/wanshan?token=" + token + "&tm=" + tm,
                                data: {
                                    "mobile": phone,
                                    "username": realname,
                                    "brand": brand,
                                    "manager_area": values,
                                    "main_product":product
                                },
                                success: function (data) {
                                    if(data.code=="1"){
                                        window.location.href="../index.html"
                                    }else{
                                        YDUI.dialog.alert(data.msg);
                                    }
                                }
                            })
                    }
                }
            })
        }
    </script>
</body>

</html>